package topday1_9.customer.bean.service;

import topday1_9.customer.bean.Customer;

/**
 * @Auther:小陈的Java
 *  客户数据业务层编写
 */
public class CustomerList {
    private Customer[] customersList;
    private int total;
    public CustomerList(int length) {
        this.customersList = new Customer[length];
    }
    public boolean add(Customer customer) {
        if(this.total>=this.customersList.length) {
            return false;
        }
        this.customersList[total++] = customer;
        return true;
    }
    public boolean modify(int index,Customer customer) {
        if(index>=this.total) {
            return false;
        }
        customersList[index] = customer;
        return true;
    }
    public boolean delete(int index) {
        if(index>=this.total) {
            return false;
        }
        for(int i=index;i<total-1;i++) {
            customersList[i] = customersList[i+1];
        }
        customersList[--total] = null;
        return true;
    }
    public Customer[] getCustomerList() {
        Customer[] customers = new Customer[total];//5  0-4
        for(int i=0;i<customers.length;i++) {
            customers[i] = this.customersList[i];
        }
        return customers;
    }
    public int getTotao() {
        return this.getTotao();
    }
    public Customer getCustomer(int index) {
        if(index>=this.total) {
            return null;
        }
        return customersList[index];
    }
}
